package com.social.servlet;

import com.social.dao.FriendDAO;
import com.social.dao.LogDAO;
import com.social.model.Friend;
import com.social.model.Log;
import com.social.model.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet("/socialCircle")
public class SocialCircleServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
        int userId = ((User) session.getAttribute("user")).getId();

        FriendDAO friendDAO = new FriendDAO();
        List<Friend> friends = friendDAO.getFriends(userId);

        LogDAO logDAO = new LogDAO();
        List<Log> publicLogs = logDAO.getLogs(userId, "public");
        List<Log> friendLogs = logDAO.getLogs(userId, "friends");
        List<Log> myLogs = logDAO.getLogs(userId, "private");

        request.setAttribute("friends", friends);
        request.setAttribute("publicLogs", publicLogs);
        request.setAttribute("friendLogs", friendLogs);
        request.setAttribute("myLogs", myLogs);

        request.getRequestDispatcher("socialCircle.jsp").forward(request, response);
    }
}